package red.internal.server.registry.channel;

import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelFutureListener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import red.internal.core.message.RegistryMessage;

/**
 * @author Jin Zheng
 * @since 2020-07-17
 */
public class NotifyListener implements ChannelFutureListener
{
	private static Logger logger = LoggerFactory.getLogger(NotifyListener.class);
	private final RegistryMessage message;

	public NotifyListener(RegistryMessage message)
	{
		this.message = message;
	}

	@Override
	public void operationComplete(ChannelFuture future) throws Exception
	{
		if (future.isSuccess())
		{
			if (logger.isDebugEnabled())
			{
				logger.debug("Notify registry message successful: name: {}, itemList: {}", message.getName(), message.getItemSet());
			}
		}
		else
		{
			logger.warn("Notify registry message failure: {}, itemList: {}", message.getName(), message.getItemSet());
		}
		Throwable throwable = future.cause();
		if (throwable != null)
		{
			logger.error("Occur exception: ", throwable);
		}
	}
}
